package com.example.androidbighomework;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.androidbighomework.utils.SaveChangePersonInfo;

import java.util.Map;

public class PersonInfoActivity extends AppCompatActivity {

    private Button btn_person_back,btn_Change_Info; //返回按钮，修改信息按钮
    private TextView mtv_info_name,mtv_info_phone,mtv_info_birth;//activity_person_info.xml里的三个TextView
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_info);
        //初始化控件
        initView();
        //获取personinfos.xml文件是否有内容，如果有内容则给三个TextView赋值
        Map<String,String> getPersonInfo= SaveChangePersonInfo.getPersonInfo(PersonInfoActivity.this);
        if(getPersonInfo!=null){
            mtv_info_name.setText(getPersonInfo.get("changename"));
            Log.i("c",getPersonInfo.get("changename"));
            mtv_info_phone.setText(getPersonInfo.get("changephone"));
            mtv_info_birth.setText(getPersonInfo.get("changebirth"));
        }
        //监听返回按钮，完成关闭当前页面
        btn_person_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //监听修改信息按钮，完成页面的跳转
        btn_Change_Info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(PersonInfoActivity.this,ChangePersonInfoActivity.class);
                startActivity(intent);
            }
        });
    }
    //再次回到activity_person_info.xml这个页面时，调用这个生命周期
    @Override
    protected void onRestart() {
        super.onRestart();
        //获取personinfos.xml文件是否有内容，如果有内容则给三个TextView赋值
        Map<String,String> getPersonInfo= SaveChangePersonInfo.getPersonInfo(PersonInfoActivity.this);
        if(getPersonInfo!=null){
            mtv_info_name.setText(getPersonInfo.get("changename"));
            Log.i("c",getPersonInfo.get("changename"));
            mtv_info_phone.setText(getPersonInfo.get("changephone"));
            mtv_info_birth.setText(getPersonInfo.get("changebirth"));
        }
    }
    //初始化控件
    private void initView() {
        btn_person_back=findViewById(R.id.person_back);
        btn_Change_Info=findViewById(R.id.btn_change_info);
        mtv_info_name=findViewById(R.id.tv_info_name);
        mtv_info_phone=findViewById(R.id.tv_info_phone);
        mtv_info_birth=findViewById(R.id.tv_info_birth);

    }

}